package com.mdd.admin.controller.order;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.log.IOrderLogService;
import com.mdd.admin.validate.log.OrderLogParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.log.OrderLogListVo;
import com.mdd.admin.vo.log.OrderLogDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单日志管理
 */
@RestController
@RequestMapping("api/order/log")
public class OrderLogController {

    @Resource
    IOrderLogService iOrderLogService;

    /**
     * 订单日志列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<OrderLogListVo> list = iOrderLogService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 订单日志详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        OrderLogDetailVo detail = iOrderLogService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 订单日志新增
     *
     * @param orderLogParam 参数
     * @return Object
     */
    @Log(title = "订单日志新增")
    @PostMapping("/add")
    public Object add(@Validated(value = OrderLogParam.create.class) @RequestBody OrderLogParam orderLogParam) {
        iOrderLogService.add(orderLogParam);
        return AjaxResult.success();
    }

    /**
     * 订单日志编辑
     *
     * @param orderLogParam 参数
     * @return Object
     */
    @Log(title = "订单日志编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = OrderLogParam.update.class) @RequestBody OrderLogParam orderLogParam) {
        iOrderLogService.edit(orderLogParam);
        return AjaxResult.success();
    }

    /**
     * 订单日志删除
     *
     * @param orderLogParam 参数
     * @return Object
     */
    @Log(title = "订单日志删除")
    @PostMapping("/del")
    public Object del(@Validated(value = OrderLogParam.delete.class) @RequestBody OrderLogParam orderLogParam) {
       // iOrderLogService.del(orderLogParam.getId());
        return AjaxResult.success();
    }

}
